#ifndef SERVERWIDGET_H
#define SERVERWIDGET_H

#include <QWidget>

#include <QThread>
#include "server.h"
#include "serverread.h"
#include "serverwrite.h"

QT_BEGIN_NAMESPACE
namespace Ui { class ServerWidget; }
QT_END_NAMESPACE

class ServerWidget : public QWidget
{
    Q_OBJECT

public:
    ServerWidget(QWidget *parent = nullptr);
    ~ServerWidget();

private:
    Ui::ServerWidget *ui;
    int m_serverFd;
    int m_clientFd;
    QString m_username;
    QString m_password;

    QThread* m_serverThread;
    QThread* m_serverReadThread;
    QThread* m_serverWriteThread;
    Server* m_server;
    ServerRead* m_serverRead;
    ServerWrite* m_serverWrite;

    void initServer();
    void initUi();
    /* 槽函数 */
    void dealServerTip(int status);
    void dealAcceptFd(int clientFd);
signals:
    void startListen();
    void startAccept();
    void startOperate(int clientFd);
    void sendMsg(QString myMsg);
    void stopThread();
};
#endif // SERVERWIDGET_H
